// VolatileClip makes movieclips fade into eachother, calling _parent.nextClip(this) when done

class com.spikything.utils.VolatileClip extends MovieClip {

	var DONE:Boolean = false;
	var FADE:Number = 12;
	var TAIL:Number = 2;
	var ALPHA:Number = 80-(FADE*TAIL);

	public function VolatileClip () {}

	public function onLoad () {
		_alpha = ALPHA;
	}
	
	public function fadeOut () {
		if  (_currentframe == _totalframes) stop();
		if (!DONE) _parent.nextClip(this);
		DONE = true;
		_alpha -= FADE;
		if (_alpha < FADE) removeMovieClip(this);
	}
	
	public function onEnterFrame () {
		if (_currentframe < _totalframes-TAIL) {
			if (_alpha < 100) _alpha += FADE;
			_alpha = Math.min(_alpha,100);
		} else {
			fadeOut();
		}
	}

}